﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using BitmapTagger;

namespace ImageTagEditor.ValueConverters
{
	/// <summary>
	/// Converts a ushort? exposure program value to its defintion and back
	/// </summary>
	public class ExposureProgramValueConverter : IValueConverter
	{


		/// <summary>
		/// Defintion for null value
		/// </summary>
		private const string NULL_DEFINITION = "Information Not Present";

		/// <summary>
		/// Get the metering mode definitions
		/// </summary>
		public List<string> Definitions
		{
			get
			{
				List<string> definitions = new List<string>();
				definitions.Add(NULL_DEFINITION);
				foreach (ushort? value in ExifValues.Instance.ExposureProgramValues)
				{
					definitions.Add(ExifValues.Instance.GetExposureProgramMeaning(value));
				}
				return definitions;
			}
		}

		/// <summary>
		/// Convert from a ushort? exposure program value to its definition
		/// </summary>
		/// <param name="value">The exposure program value</param>
		/// <param name="targetType">Not Used</param>
		/// <param name="parameter">Not Used</param>
		/// <param name="culture">Not Used</param>
		/// <returns>The defnition of the exposure program value</returns>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value == null)
				return NULL_DEFINITION;
			if (value is ushort?)
				return ExifValues.Instance.GetExposureProgramMeaning((ushort?)value);
			throw new Exception("Can only convert values of type ushort?");
		}

		/// <summary>
		/// Convert back from a exposure program definition to its ushort? value
		/// </summary>
		/// <param name="value">The exposure program defintion</param>
		/// <param name="targetType">Not Used</param>
		/// <param name="parameter">Not Used</param>
		/// <param name="culture">Not Used</param>
		/// <returns>The exposure program value of the definition</returns>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value is string)
			{
				if (value.Equals(NULL_DEFINITION))
					value = ExifValues.NULL_MEANING;
				return ExifValues.Instance.GetExposureProgramValue((string)value);
			}
			throw new NotImplementedException("Can only convert values of type string");
		}


	}
}
